package com.cirkana.viewer.security.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;

import com.cirkana.serial.SerializablePassData;
import com.cirkana.serial.SerializationException;

public class Profile extends SerializablePassData {

	private Credential cirkanaCredential;
	private ArrayList<Credential> credentials;

	// TODO: Should be protected
	public Profile() {
	}

	public Credential getCirkanaCredential() {
		return cirkanaCredential;
	}

	public void setCirkanaCredential(Credential cirkanaCredential) {
		this.cirkanaCredential = cirkanaCredential;
	}

	public ArrayList<Credential> getCredentials() {
		return credentials;
	}

	public void setCredentials(ArrayList<Credential> credentials) {
		this.credentials = credentials;
	}

	@Override
	public void serialize(DataOutputStream out) throws SerializationException {
		serializeSerializable(this.cirkanaCredential, out);
		serializeSerializableList(this.credentials, Credential.class, out);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void deserialize(DataInputStream in) throws SerializationException {
		this.cirkanaCredential = (Credential) deserializeSerializable(Credential.class, in);
		this.credentials = deserializeSerializableList(Credential.class, in);
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder("{");

		s.append("cirkanaCredential=");
		if (this.cirkanaCredential == null)
			s.append("(null)");
		else
			s.append(this.cirkanaCredential.toString());
		s.append(",credentials=");
		if (this.credentials == null)
			s.append("(null)");
		else {
			s.append("{");
			for (Credential credential : this.credentials) {
				if (credential == null)
					s.append("(null)");
				else
					s.append(credential.toString());
				s.append(",");
			}
			s.delete(s.length(), s.length());
			s.append("}");
		}
		s.append("}");

		return s.toString();
	}
}
